package cmd

import (
	"context"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
	"mongofix/stat"
)

const (
	StatUser = "group"
)

var statGroupByUser bool
var isSendMail bool
var statGroupByDay bool

var statCmd = &cobra.Command{
	Use:     "stat",
	Short:   "统计功能",
	Long:    "统计功能",
	Version: "1.0",
	Run:     StatRun,
}

func StatRun(cmd *cobra.Command, args []string) {
	if len(args) <= 0 {
		log.Infof("缺少groupId参数")
		return
	}
	if statGroupByUser {
		ctx := context.Background()
		stat.StatGroupByUser(ctx, args[0], isSendMail)
	}
	if statGroupByDay {
		ctx := context.Background()
		stat.StatGroupByDay(ctx, args[0], isSendMail)
	}
}

func init() {
	statCmd.Flags().BoolVarP(&statGroupByUser, "sgbu", "u", false, "按用户统计群信息")
	statCmd.Flags().BoolVarP(&isSendMail, "send", "s", false, "是否发送邮件")
	statCmd.Flags().BoolVarP(&statGroupByDay, "sgbd", "d", false, "按用天统计群信息")
	rootCmd.AddCommand(statCmd)
}
